search.parse();

var delayTime = 0;
var form = new Form('userphone-form');
var userphone = search.get('userphone');
var vercodebtn = $(".vercodebtn");

// 保存
function save() {
	if (!form.validate()) {
		return;
	}
	var formdata = form.getData();
	$.post(__ctx + '/main/updateUserphone.xhtml', formdata, function(result) {
		if (result.status) {
			top.search.info({content : '修改成功！', funl : function() {
				window.closeWindow(formdata);
			}});
		} else {
			SearchUtils.msg(result.result);
		}
	});
}

// 获取验证码
function getVercode() {
	if (vercodebtn.hasClass("disabled")) return;
	if (!userphone.validate()) return;
	
	$.post(__ctx + '/nr/api/aliyun/getVercode.xhtml', {userphone : userphone.getValue()}, function(result) {
		if (result.status) {
			delayTime = 60;
			vercodebtn.addClass("disabled");
			vercodebtn.children("span").text(delayTime + "s");
			setTimeout(timeoutHandler, 1000);
		} else {
			SearchUtils.msg("发送验证码失败！");
		}
	});
}

// 超时处理器
function timeoutHandler() {
	delayTime --;
	if (delayTime <= 0) {
		vercodebtn.removeClass("disabled");
		vercodebtn.children("span").text("");
		return;
	}
	
	vercodebtn.children("span").text(delayTime + "s");
	setTimeout(timeoutHandler, 1000);
}
